﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;

namespace ClientAppraise.Controls
{
    public class ZxFormItem : System.Windows.Controls.ContentControl
    {
        public static readonly DependencyProperty TitleProperty;
        public static readonly DependencyProperty IsRequestProperty;
        public static readonly DependencyProperty TipsProperty;

        private static readonly DependencyProperty HasTitleProperty;
        private static readonly DependencyProperty HasTipsProperty;

        public static readonly DependencyProperty OrientationProperty;

        public static readonly DependencyProperty TitleWidthProperty;

        static ZxFormItem()
        {
            TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(ZxFormItem), new PropertyMetadata(null, TitleChangedCallback));
            IsRequestProperty = DependencyProperty.Register(nameof(IsRequest), typeof(bool), typeof(ZxFormItem));
            TipsProperty = DependencyProperty.Register(nameof(Tips), typeof(object), typeof(ZxFormItem), new PropertyMetadata(null, TipsChangedCallback));

            HasTitleProperty = DependencyProperty.Register(nameof(HasTitle), typeof(bool), typeof(ZxFormItem));
            HasTipsProperty = DependencyProperty.Register(nameof(HasTips), typeof(bool), typeof(ZxFormItem));

            OrientationProperty = DependencyProperty.Register(nameof(Orientation), typeof(Orientation), typeof(ZxFormItem), new PropertyMetadata(Orientation.Vertical));

            TitleWidthProperty = DependencyProperty.Register(nameof(TitleWidth), typeof(double), typeof(ZxFormItem));
        }

        public string Title
        {
            get => (string)GetValue(TitleProperty);
            set => SetValue(TitleProperty, value);
        }
        public object Tips
        {
            get => GetValue(TipsProperty);
            set => SetValue(TipsProperty, value);
        }
        public bool IsRequest
        {
            get => (bool)GetValue(IsRequestProperty);
            set => SetValue(IsRequestProperty, value);
        }

        public bool HasTips
        {
            get => (bool)GetValue(HasTipsProperty);
            set => SetValue(HasTipsProperty, value);
        }
        public bool HasTitle
        {
            get => (bool)GetValue(HasTitleProperty);
            set => SetValue(HasTitleProperty, value);
        }

        public Orientation Orientation
        {
            get => (Orientation)GetValue(OrientationProperty);
            set => SetValue(OrientationProperty, value);
        }

        public double TitleWidth
        {
            get => (double)GetValue(TitleWidthProperty);
            set => SetValue(TitleWidthProperty, value);
        }

        private static void TitleChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is not ZxFormItem control)
            {
                return;
            }

            control.SetValue(HasTitleProperty, e.NewValue != null);
        }
        private static void TipsChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is not ZxFormItem control)
            {
                return;
            }

            control.SetValue(HasTipsProperty, e.NewValue != null);
        }
    }

}
